<template>
    <div>
        <el-dialog :title="dialogInfo.title" :visible.sync="dialogInfo.isShow">
            <el-form :model="formInfo" label-width="100px">
                <el-form-item label="商品名称">
                    <el-input v-model="formInfo.goods_name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="商品价格">
                    <el-input v-model="formInfo.goods_price" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="商品数量">
                    <el-input v-model="formInfo.goods_number" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="商品重量">
                    <el-input v-model="formInfo.goods_weight" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="商品图片">
                    <el-button type="primary">点击上传</el-button>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogInfo.isShow = false">取 消</el-button>
                <el-button type="primary" @click="queryBtn">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { addGoodsApi } from '@/api/goods';
export default {
    name: 'MyAppDialogCom',
    props: {
        dialogInfo: {
            type: Object
        }
    },
    data() {
        return {
            formInfo: {
                goods_name: "",
                goods_price: "",
                goods_number: "",
                goods_weight: "",
                goods_cat:`${this.cartNum},${this.cartNum},${this.cartNum}`
            },
            cartNum:''
        };
    },
    // 分类列表随机数
    created() {
        this.cartNum = Math.floor(Math.random() * 100000)
    },
    mounted() {

    },

    methods: {
        async queryBtn() {
            if (this.dialogInfo.options == 'add') {
                try {
                    await addGoodsApi(this.formInfo)
                    this.$message.success('添加成功')
                } catch (error) {
                    this.$message.error('添加失败')
                }

            }
            this.$emit('addBtn');
            this.formInfo = {
                goods_name: "",
                goods_price: "",
                goods_number: "",
                goods_weight: "",
                goods_cat: '[]'
            }
            this.dialogInfo.isShow = false
        }
    },
};
</script>

<style lang="scss" scoped>

</style>